package com.atguigu.controller;

import com.atguigu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class TestGetParamsController {


    @RequestMapping(value = "/params/servletAPI",method = RequestMethod.POST)
    public String getParamByServletAPI(HttpServletRequest httpServletRequest){

        //先在一个方法中使用Session创建一个cookie
        HttpSession session = httpServletRequest.getSession();
        String username = httpServletRequest.getParameter("username");
        String id = httpServletRequest.getParameter("id");

        System.out.println("username:"+username+"id"+id);

        return "success";
    }

    @RequestMapping(value = "/params",method = RequestMethod.POST)
    public String getParamByServletAPI(@RequestParam("Username") String username,
                                       @RequestParam("ID") Integer id,
                                       @RequestHeader("referer") String referer,
                                       @CookieValue("JSESSIONID") String jsessionId){
        System.out.println("username:"+username+"id"+id);
        System.out.println("referer:"+referer);
        System.out.println("JSESSIONID:"+jsessionId);
        return "success";
    }

    @RequestMapping(value = "/params/getParamsByPojo",method = {RequestMethod.POST,RequestMethod.GET})
    public String getParamsByPojo(User user){
        System.out.println(user);
        return "success";

    }

}
